<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//菜单管理
class Menus extends CommonController {

	function __construct(){
		
		parent::__construct();
		$this->load->dmodel('menus','CurModel');
		
	}
	
	
	//start
	/**
	* @name 获取列表
	* @return 成功返回array
	*/
	//end
	function get_menu(){
		$user_id = $this->user_id;
		$info = array();
		$row = $this->CurModel->getRow(array('user_id'=>$user_id));
		if($row){
			$ls_data = json_decode($row['data'],true);
			if($ls_data){
				$info = $ls_data;
			}
			
		}
		
		$this->data_out($info);
	}
	

	
	//start
	/**
	* @name 保存
	* @param info 
	* @return 成功返回array
	*/
	//end
	function save(){
		$user_id = $this->user_id;
		$info = $this->input->post('info',null,array());
		if(!is_array($info)){
			$info = explode(',',$info);
		}

		$data = json_encode($info);
		
		
		$is_exist = $this->CurModel->_where_exist(array('user_id'=>$user_id));
		if($is_exist){
			$this->CurModel->edit(array('data'=>$data),"user_id='{$user_id}'");
		}
		else{
			$this->CurModel->add(array('data'=>$data,"user_id"=>$user_id));
		}

		$this->add_log("设置菜单项",'menus');
		$this->data_out(1);
	}
	
	
	
}
